package com.xinqi.modules.stats.score.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.modules.stats.score.dto.req.*;
import com.xinqi.modules.stats.score.dto.rsp.CourseTotalScoreOfflineConfigResultDTO;
import com.xinqi.modules.stats.score.service.CourseTotalScoreOfflineConfigService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreOfflineService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 线下成绩等级分值设置WEB控制层
 *
 * @author: system
 * @date: 2023/03/26
 */
@Tag(name = "线下成绩等级分值设置表Web接口", description = "线下成绩等级分值设置表Web接口")
@RestController
@RequestMapping("/web/total-score-offline-config")
@RequiredArgsConstructor
public class CourseTotalScoreOfflineConfigWebController {

    private final CourseTotalScoreOfflineConfigService courseTotalScoreOfflineConfigService;

    private final CourseTotalScoreOfflineService courseTotalScoreOfflineService;

    /**
     * 根据课程内容获取等级分制WEB配置列表
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/list")
    public R<List<CourseTotalScoreOfflineConfigResultDTO>> list(CourseTotalScoreOfflineConfigQueryDTO dto) {
        return R.ok(courseTotalScoreOfflineConfigService.findCourseTotalScoreOfflineConfig(dto));
    }

    /**
     * 等级评分模式开关(用于课程内容分类)
     * @param dto 设置
     * @return
     */
    @PostMapping("/level/set")
    public R<String> levelSet(@Validated @RequestBody CourseTotalScoreOfflineUpdateDTO dto) {
        if (courseTotalScoreOfflineService.updateById(dto)) {
            return R.ok("设置成功");
        } else {
            return R.fail("设置失败");
        }
    }

    /**
     * 设置等级评分模式
     * @param dto 设置
     * @return
     */
    @PostMapping("/set")
    public R set(@Validated @RequestBody CourseTotalScoreOfflineConfigSetDTO dto) {
        if (courseTotalScoreOfflineConfigService.setCourseTotalScoreOfflineConfig(dto)) {
            return R.ok("设置成功");
        } else {
            return R.fail("设置失败");
        }
    }

    /**
     * 课程内容等级制分制WEB恢复默认接口
     * @param dto 设置
     * @return
     */
    @PostMapping("/recover")
    public R<List<CourseTotalScoreOfflineConfigResultDTO>> recover(@Validated @RequestBody CourseTotalScoreOfflineConfigQueryDTO dto) {
        List<CourseTotalScoreOfflineConfigResultDTO> list = courseTotalScoreOfflineConfigService.initCourseTotalScoreOfflineConfig(dto);
        if (list != null) {
            return R.data(list);
        } else {
            return R.fail("恢复失败");
        }
    }

}
